# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-ppx_sexp_conv
_pkgname=ppx_sexp_conv
pkgver=0.16.0
pkgrel=0
pkgdesc="[@@deriving] plugin to generate S-expression conversion functions"
url="https://github.com/janestreet/ppx_sexp_conv"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-base-dev
	ocaml-ppxlib-dev
	ocaml-sexplib0-dev
	"
makedepends="$depends_dev dune ocaml"
subpackages="$pkgname-dev"
source="https://ocaml.janestreet.com/ocaml-core/v${pkgver%.*}/files/ppx_sexp_conv-v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-v$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --build-dir=.testenv --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
898549b8fdac328bf4583b3ee744b7fed59bb22ebcf9d5afe4268985c60f5d7b04881a7e77fc2940776afb21669e96411a244b5e4902af737c673f0cce63bb55  ppx_sexp_conv-v0.16.0.tar.gz
"
